package com.kc.gb.device.configurations;

/**
 * @author : evan.liu
 * @version V1.0
 * @Description: TODO
 * @date Date : 2022年05月01日 3:31 上午
 */

import com.kc.gb.base.dto.Result;
import com.kc.gb.device.common.dto.I18NException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(I18NException.class)
    public Result handleDeviceException(HttpServletRequest req, I18NException e) throws Exception {
        log.info("ExceptionHandler |I18NException:{}",e.getMessage(),e);
        try {
        } catch (Exception exception) {
            log.info(e.getMessage());
        }
        // 正常返回
        Result ret = Result.fail(e.getMessage());
        return ret;
    }

    @ExceptionHandler(Throwable.class)
    public Result handleThrowable(HttpServletRequest req, Throwable e) throws Exception {
        log.info("ExceptionHandler |Throwable:{}",e.getMessage(),e);
        try {
            //GlobalExceptionUtils.handleGlobalException(e);
        } catch (Exception exception) {
            log.info(e.getMessage());
        }
        // 正常返回
        Result ret = Result.fail(e.getMessage());
        return ret;
    }
}

